//返回值统一管理工具
class BackCode {
    constructor({ code, data, msg }) {
        this.code = code,
            this.data = data,
            this.msg = msg
    }
    // 成功且只返回code
    static buildSuccess() {
        return new BackCode({ code: 0, data: null, msg: null }).toJson()
    }
    // 成功且无信息
    static buildSuccessAndMsg({ msg }) {
        return new BackCode({ code: 0, data: null, msg }).toJson()
    }
    // 成功有信息
    static buildSuccessAndData({ data }) {
        return new BackCode({ code: 0, data, msg: null }).toJson()
    }
    // 失败有信息
    static buildError({ msg }) {
        return new BackCode({ code: -1, data: null, msg }).toJson()
    }
    // 自定义信息
    static buildResult(codeEnum) {
        return new BackCode({ code: codeEnum.code, data: codeEnum?.data || null, msg: codeEnum.msg }).toJson()
    }
    toJson() {
        return {
            code: this.code,
            data: this.data,
            msg: this.msg
        }
    }
}
module.exports = BackCode